package cn.tedu.wxdemo.domain;

import lombok.Data;

import java.io.Serializable;


/**
 * 该类为Access_token存储bean
 */
@Data
public class AccessTokenBean implements Serializable {

    /* 固定值 */
    private String grant_type = "client_credential";
    /* 获取的accessToken */
    private String accessToken;
    /* 过期时间 */
    private Long expiresTime;

    public AccessTokenBean(String accessToken, Long expiresTime) {
        this.accessToken = accessToken;
        if(expiresTime>0){
            this.expiresTime = System.currentTimeMillis()+expiresTime*1000;
        }
    }

    /**
     * 构建access_token对象
     * @param accessToken token
     * @param expiresTime 过期时间
     * @return {@link AccessTokenBean}
     */
    public static AccessTokenBean responseOf(String accessToken,long expiresTime){
        return new AccessTokenBean(accessToken,expiresTime);
    }

    /**
     * 是否过期
     * @return
     */
    public boolean isExpired(){
        return System.currentTimeMillis() > expiresTime;
    }
}
